package aps

import cn.hutool.json.JSONUtil
import glory.xxd.Utils

/**
 * 点击开始作业按钮
 */
class StartProcessController {

    def commentService

    /**
     * <Request>
     <Header>
     <TRANSACTIONID>8c3f8423-51ef-4a23-bb38-a26aba909db5</TRANSACTIONID>
     <MESSAGENAME>StartProcess</MESSAGENAME>
     <USERNAME>EAP</USERNAME>
     </Header>
     <Body class="Body">
     <USERNAME>G2976</USERNAME>
     <LotId>LMBT3906LT1G^M3CG3906^88ASB02473L^EJ1WCR-022</LotId>
     <TotalQty>211756</TotalQty>
     <EqpId>1FS05</EqpId>
     <INPUTDATALIST>
     <INPUTDATA>
     <DATANAME>ParamName</DATANAME>
     <DATAVALUE>录入内容<DATAVALUE>
     </INPUTDATA>
     <INPUTDATA>
     <DATANAME>ParamName</DATANAME>
     <DATAVALUE>内容<DATAVALUE>
     </INPUTDATA>
     </INPUTDATALIST>
     </Body>
     </Request>
     * @return
     */
    def index() {

        try {
            def EqpId = params.EqpId ?: ""
            def USERNAME = params.USERNAME ?: ""
            def LotId = params.LotId ?: ""
            def TotalQty = params.TotalQty ?: ''
            def StartMode = params.StartMode ?: ''
            String logUUID = Utils.getUUID();

            def header = [MESSAGENAME: "StartProcess", TRANSACTIONID: logUUID, USERNAME: "EAP"]
            header = "<Header>${Utils.getXmlByJSONHtml(header)}</Header>"

            def InputDataList =params.InputDataList
            def isJsonArray = JSONUtil.isJsonArray(InputDataList)
            print isJsonArray
            if (isJsonArray) {
                InputDataList = Utils.getXmlByJSONArray(InputDataList)
            } else {
                InputDataList = Utils.getXmlByJSONHtml(InputDataList)
            }

            def body = [EqpId: EqpId, USERNAME: USERNAME, LotId: LotId, TotalQty: TotalQty, StartMode: StartMode,INPUTDATALIST:InputDataList]

            body = "<Body>${Utils.getXmlByJSONHtml(body)}</Body>"
            def xml = "<Request>${header}${body}</Request>"
            def json = commentService.getJsonByObjectForTopic2Queue(logUUID, xml)
            //println xmlf
            render json
        } catch (Exception e) {
            e.printStackTrace()
        }
    }

}